package com.huawei.appmarket.service.distribution.minidetail;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSSelector;
import com.huawei.appgallery.foundation.ui.css.CSSStyleSheet;
import com.huawei.appgallery.foundation.ui.css.CSSView;
import com.huawei.appgallery.foundation.ui.css.adapter.CSSPropertyName;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSMonoColor;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSValue;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.appmarket.R;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailDescBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailPermissionBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailPermissionBean.DetailPermissionItemBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailScreenBean;
import com.huawei.appmarket.service.appdetail.view.card.DetailDescCardEx;
import com.huawei.appmarket.service.appdetail.view.card.DetailGradeCard;
import com.huawei.appmarket.service.appdetail.view.card.DetailHeadCard;
import com.huawei.appmarket.service.appdetail.view.card.DetailHiddenCard;
import com.huawei.appmarket.service.appdetail.view.card.DetailPermissionCard;
import com.huawei.appmarket.service.appdetail.view.card.DetailScreenCard;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import o.cjk;
import o.ckd;
import o.dgh;
import o.dmt;
import o.dph;
import o.drd;
import o.drr;
import o.dry;
import o.dvq;
import o.dvt;
import o.dxh;
import o.dxi;
import o.dxq;
import o.CollectCheck;
import o.eqp;

public class MiniDetailFragment extends MiniDetailAbstractFragment implements dxh {
    private boolean ʼ = false;
    private BroadcastReceiver ʽ = new BroadcastReceiver(this) {
        final /* synthetic */ MiniDetailFragment ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceive(Context context, Intent intent) {
            if (this.ˊ.ˋ != null) {
                this.ˊ.ˋ.ॱ();
            }
        }
    };
    private drr ˎ = new drr();

    protected void ˎ(Bundle bundle) {
        if (!(CollectCheck.isEmpty(this.ॱ.ॱ()) || this.ॱ.ˊ() == null || this.ॱ.ˏ() == null)) {
            ॱˋ(true);
        }
        if (bundle != null) {
            this.ʼ = bundle.getBoolean("start_download_already", false);
        }
    }

    @Nullable
    public View ˋ(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
        View ˋ = super.ˋ(layoutInflater, viewGroup, bundle);
        ॱˋ().registerReceiver(this.ʽ, new IntentFilter(dvq.ˊ()));
        ˎ(ˋ);
        return ˋ;
    }

    protected void ॱ(ViewGroup viewGroup) {
        super.ॱ(viewGroup);
        if (this.ॱ.ˊ().ॱـ() != null) {
            drd.ˏ(this.ॱ.ˊ().ॱـ(), this.ॱ.ˊ().ˎˎ());
        }
    }

    public void ˊ(@NonNull View view, @Nullable Bundle bundle) {
        super.ˊ(view, bundle);
        ॱ();
        if (this.ॱ.ͺ() && !this.ʼ) {
            this.ʼ = true;
            final DetailHiddenBean ˊ = this.ॱ.ˊ();
            SessionDownloadTask ˋ = dvt.ˏ().ˋ(ˊ.ॱـ());
            if (ˋ == null) {
                dxq.ˏ(ˊ, new c(this) {
                    final /* synthetic */ MiniDetailFragment ˋ;

                    public void ˎ(@Nullable SessionDownloadTask sessionDownloadTask) {
                        if (sessionDownloadTask != null) {
                            sessionDownloadTask.ॱˊ(this.ˋ.ॱ.ˊॱ());
                            sessionDownloadTask.ˋॱ(8);
                            if (sessionDownloadTask.ˊˋ() < 157286400 && String.valueOf(1).equals(this.ˋ.ॱ("advPlatform")) && !dxi.ˏ(this.ˋ.ॱ.ʻॱ())) {
                                sessionDownloadTask.ˏ(true);
                            }
                            this.ˋ.ˋ(ˊ, sessionDownloadTask, 0, false);
                        }
                    }
                });
            } else if (ˋ.ˈ() == 6 || ˋ.ˈ() == -1) {
                ˋ(ˊ, ˋ, ˋ.ʼॱ(), true);
            }
        }
    }

    private void ˋ(DetailHiddenBean detailHiddenBean, SessionDownloadTask sessionDownloadTask, int i, boolean z) {
        if (dxi.ॱ(ॱˊ(), this.ॱ.ʻॱ(), this.ॱ.ᐝॱ())) {
            String str = null;
            if (!z) {
                str = dph.ˋ().ˊ(sessionDownloadTask);
            }
            cjk.ˎ().ˋ(ॱˊ(), dxi.ॱ(detailHiddenBean.ॱـ(), detailHiddenBean.ˉ(), i, str, z));
            return;
        }
        sessionDownloadTask.ˋॱ(8);
        if (z) {
            dvt.ˏ().ˊ(sessionDownloadTask.ʾ());
        } else {
            dvt.ˏ().ॱ(sessionDownloadTask, false);
        }
    }

    private void ॱ() {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("detailId", this.ॱ.ˊ().ॱॱ());
        linkedHashMap.put("isReady", String.valueOf(this.ॱ.ˊ().ˌ()));
        linkedHashMap.put("advPlatform", ॱ("advPlatform"));
        linkedHashMap.put("mediaPkg", ॱ("mediaPkg"));
        linkedHashMap.put("advInfo", ॱ("advInfo"));
        linkedHashMap.put("referrer", ॱ("referrer"));
        linkedHashMap.put(HwPayConstant.KEY_COUNTRY, eqp.ॱ());
        linkedHashMap.put("accessID", this.ॱ.ॱˎ());
        CharSequence ॱˋ = this.ॱ.ॱˋ();
        linkedHashMap.put("detailType", ॱˋ);
        if (TextUtils.isEmpty(ॱˋ)) {
            linkedHashMap.put("callWay", String.valueOf(1));
        } else {
            linkedHashMap.put("callWay", String.valueOf(2));
        }
        dgh.ˋ("380501", linkedHashMap);
    }

    public String ॱ(String str) {
        if (TextUtils.isEmpty(this.ॱ.ˊॱ()) || TextUtils.isEmpty(str)) {
            return null;
        }
        return (String) dmt.ˊ(this.ॱ.ˊॱ()).get(str);
    }

    protected void ˏ(@NonNull LayoutInflater layoutInflater, @Nullable Bundle bundle, ViewGroup viewGroup) {
        LinearLayout linearLayout = (LinearLayout) viewGroup.findViewById(R.id.mini_detail_container);
        for (b bVar : this.ˎ.ˏ()) {
            if (!(bVar.ˊ == null || (bVar.ˊ instanceof DetailHeadCard) || (bVar.ˊ instanceof DetailHiddenCard) || bVar.ʼ() == null || bVar.ʼ().size() <= 0)) {
                bVar.ˊ.ˏ(this);
                ˏ(bVar);
                View ˊ = bVar.ˊ.ˊ(layoutInflater, linearLayout, bundle);
                if (ˊ != null) {
                    bVar.ˊ.ॱ(bVar.ᐝ());
                    if (bVar.ˊ.ˊ(bVar.ʼ()) && bVar.ˊ.ˊ(bVar)) {
                        if (bVar.ˊ() != null) {
                            CSSView.wrap(ˊ, bVar.ˊ()).render();
                        }
                        bVar.ˊ.ॱ();
                        linearLayout.addView(ˊ);
                    }
                }
            }
        }
    }

    private void ˏ(b bVar) {
        if (bVar.ˊ instanceof DetailPermissionCard) {
            bVar.ˊ = new DetailDescCardEx();
            List<JsonBean> ʼ = bVar.ʼ();
            List arrayList = new ArrayList();
            for (JsonBean jsonBean : ʼ) {
                if (jsonBean instanceof DetailPermissionBean) {
                    DetailDescBean detailDescBean = new DetailDescBean();
                    DetailPermissionBean detailPermissionBean = (DetailPermissionBean) jsonBean;
                    detailDescBean.ʾ(detailPermissionBean.v_());
                    StringBuilder stringBuilder = new StringBuilder();
                    for (DetailPermissionItemBean detailPermissionItemBean : detailPermissionBean.ॱ()) {
                        stringBuilder.append(detailPermissionItemBean.ˋ()).append(detailPermissionItemBean.ˏ()).append("\n\n");
                    }
                    detailDescBean.ˈ(stringBuilder.toString());
                    arrayList.add(detailDescBean);
                }
            }
            ʼ.clear();
            bVar.ˋ(arrayList);
        }
        if (bVar.ˊ instanceof DetailGradeCard) {
            ((DetailGradeCard) bVar.ˊ).ॱ(true);
        }
        if (bVar.ˊ instanceof DetailScreenCard) {
            for (JsonBean jsonBean2 : bVar.ʼ()) {
                if (jsonBean2 instanceof DetailScreenBean) {
                    ((DetailScreenBean) jsonBean2).ॱॱ(null);
                }
            }
        }
    }

    protected void ˎ(@Nullable ViewGroup viewGroup, @Nullable Bundle bundle, ViewGroup viewGroup2) {
        if (this.ॱ.ˏ() != null) {
            this.ॱ.ˏ().ˊ(false);
        }
        super.ˎ(viewGroup, bundle, viewGroup2);
    }

    private void ˎ(View view) {
        int i = 0;
        if (this.ॱ.ʻ() == null || this.ॱ.ʽ() == null) {
            view.setBackgroundColor(ᐝॱ().getColor(R.color.emui_white));
            return;
        }
        CSSRule rule = new CSSSelector(this.ॱ.ʽ()).getRule(CSSStyleSheet.parse(this.ॱ.ʻ()).getRootRule());
        if (rule != null) {
            CSSView.wrap(view, rule).render();
            if (this.ॱ.ʼ() == 1) {
                int color;
                CSSMonoColor ˏ = ˏ(rule, ".body", CSSPropertyName.BACKGROUND_COLOR);
                if (ˏ != null) {
                    color = ˏ.getColor();
                    view.setBackgroundColor(color);
                    this.ˏ.ॱ(color);
                }
                ˏ = ˏ(rule, ".widget", CSSPropertyName.BACKGROUND_TINT);
                if (ˏ != null) {
                    color = ˏ.getColor();
                } else {
                    color = 0;
                }
                CSSMonoColor ˏ2 = ˏ(rule, ".detail-download-button", CSSPropertyName.FONT_COLOR);
                if (ˏ2 != null) {
                    i = ˏ2.getColor();
                }
                if (color != 0 && i != 0) {
                    ckd o_dry = new dry(ॱˋ(), color, i);
                    this.ˊ.setTextColor(-16777216);
                    this.ˋ.setButtonStyle(o_dry);
                    this.ˋ.ॱ();
                }
            }
        }
    }

    private CSSMonoColor ˏ(CSSRule cSSRule, String str, String str2) {
        CSSRule rule = new CSSSelector(str).getRule(cSSRule);
        if (rule == null || rule.getStyleDeclaration() == null) {
            return null;
        }
        CSSValue propertyValue = rule.getStyleDeclaration().getPropertyValue(str2);
        return propertyValue instanceof CSSMonoColor ? (CSSMonoColor) propertyValue : null;
    }

    public void ˏ(drr o_drr) {
        this.ˎ = o_drr;
    }

    public void ˎˎ() {
        ॱˋ().unregisterReceiver(this.ʽ);
        super.ˎˎ();
    }

    public void ˋ(@NonNull Bundle bundle) {
        bundle.putBoolean("start_download_already", this.ʼ);
        super.ˋ(bundle);
    }
}
